libxl: remove stubdom device model save file when destroying stubdom
authorIan Campbell <ian.campbell@citrix.com>
Thu, 15 Dec 2011 16:56:21 +0000 (16:56 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 15 Dec 2011 16:56:21 +0000 (16:56 +0000)
/var/lib/xen/qemu-save.<domid> is created when the stub domain is started
(connected to a stubdom console) and is used to save the device model state on
suspend/migrate but never cleaned up.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_dm.c
tools/libxl/libxl_dom.c
tools/libxl/libxl_internal.h

index 8eddd6fd23482502f7a83ebf836a6220e18d0a60..2c1fcd4f24ab93a7f248f6b391eaa0478fbeea40 100644 (file)
@@ -36,6 +36,11 @@ static const char *libxl_tapif_script(libxl__gc *gc)
 #endif
 }
 
+const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid)
+{
+    return libxl__sprintf(gc, "/var/lib/xen/qemu-save.%d", domid);
+}
+
 const char *libxl__domain_device_model(libxl__gc *gc,
                                        libxl_device_model_info *info)
 {
@@ -721,7 +726,8 @@ retry_transaction:
                 free(filename);
                 break;
             case STUBDOM_CONSOLE_SAVE:
-                console[i].output = libxl__sprintf(gc, "file:"SAVEFILE".%d", info->domid);
+                console[i].output = libxl__sprintf(gc, "file:%s",
+                                libxl__device_model_savefile(gc, info->domid));
                 break;
             case STUBDOM_CONSOLE_RESTORE:
                 if (info->saved_state)
@@ -924,6 +930,8 @@ int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)
     pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
     if (!pid) {
         int stubdomid = libxl_get_stubdom_id(ctx, domid);
+        const char *savefile;
+
         if (!stubdomid) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't find device model's pid");
             ret = ERROR_INVAL;
@@ -933,6 +941,20 @@ int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)
         ret = libxl_domain_destroy(ctx, stubdomid, 0);
         if (ret)
             goto out;
+
+        savefile = libxl__device_model_savefile(gc, domid);
+        ret = unlink(savefile);
+        /*
+         * On suspend libxl__domain_save_device_model will have already
+         * unlinked the save file.
+         */
+        if (ret && errno == ENOENT) ret = 0;
+        if (ret) {
+            LIBXL__LOG_ERRNO(ctx, XTL_ERROR,
+                             "failed to remove device-model savefile %s\n",
+                             savefile);
+            goto out;
+        }
     } else {
         ret = kill(atoi(pid), SIGHUP);
         if (ret < 0 && errno == ESRCH) {
index a0c859ed0ba57373d8e73d5edef8c707dce285c8..768360143ac324110365488c8635855f24c5c6c2 100644 (file)
@@ -608,7 +608,7 @@ int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd)
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int fd2, c;
     char buf[1024];
-    char *filename = libxl__sprintf(gc, "/var/lib/xen/qemu-save.%d", domid);
+    const char *filename = libxl__device_model_savefile(gc, domid);
     struct stat st;
     uint32_t qemu_state_len;
 
index bbd747340043f785d8207659ca90f0a5a992405e..cd2d67fe27aed03e234df146c0dbf54456aa66a5 100644 (file)
@@ -59,7 +59,6 @@
 #define STUBDOM_CONSOLE_RESTORE 2
 #define STUBDOM_CONSOLE_SERIAL 3
 #define STUBDOM_SPECIAL_CONSOLES 3
-#define SAVEFILE "/var/lib/xen/qemu-save"
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
@@ -244,6 +243,7 @@ _hidden int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__domain_suspend_common(libxl__gc *gc, uint32_t domid, int fd,
                                          libxl_domain_type type,
                                          int live, int debug);
+_hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid);
 _hidden int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd);
 _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);